package com.smbms.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smbms.pojo.User;
import com.smbms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//测试改
import java.util.List;
//冲突4
//冲突2
//冲突3
//test
//fgjgk g55555
//

@Controller
@CrossOrigin(origins = "*",maxAge = 3600)
public class UserController {
//123
    @RequestMapping("/getDataJsonp")
    @ResponseBody
    public  List<User> getJsonData(){
        return userService.findAll();
    }

    @Autowired
    private UserService userService;

    @RequestMapping("/login.do")
    public String login(User user){
        User login = userService.login(user);
        if (login==null){
            return "login";
        }
        return "welcome";
    }

    @RequestMapping("/userList.do")
    public String showList(Model model,Integer page){
        if (page==null){
            page=1;
        }
        //设置分页信息
        Page<Object> startPage = PageHelper.startPage(page, 2);
        List<User> list = userService.findAll();
        PageInfo<User> pageInfo=new PageInfo<User>(list,5);

        model.addAttribute("pageInfo",pageInfo);
        return "userList";
    }

    @RequestMapping("/getData")
    @ResponseBody
    public String showData(String callback){
        System.out.println(callback);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("name","hello world");
        String message=callback+"("+jsonObject+")";
        return message;
    }


}
